package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Expenditure;
import cn.wolfcode.crm.mapper.ExpenditureMapper;
import cn.wolfcode.crm.query.ExpenditureQueryObject;
import cn.wolfcode.crm.service.IExpenditureService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExpenditureServiceImpl implements IExpenditureService {
    @Autowired
    private ExpenditureMapper mapper;
    public void save(Expenditure expenditure) {
        mapper.insert(expenditure);

    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void update(Expenditure expenditure) {
        System.out.println(expenditure);
        mapper.updateByPrimaryKey(expenditure);
    }

    public Expenditure get(Long id) {
        Expenditure expenditure = mapper.selectByPrimaryKey(id);
        return expenditure;
    }

    public List<Expenditure> listAll() {
        List<Expenditure> list = mapper.selectAll();
        return list;
    }


    public PageResult query(ExpenditureQueryObject qo) {
        //1:查总条数
        int total = mapper.queryForCount(qo);
        System.out.println(qo);

        if(total == 0){
            return new PageResult();
        }
        //2:查分页数据
        List<Expenditure> rows = mapper.queryForList(qo);

        return new PageResult(total, rows);
    }
}
